<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
</head>
<body>
    <input type="button" value="赞(1)">
    <input type="button" value="赞(1)">
    <input type="button" value="赞(1)">
    <input type="button" value="赞(1)">
    <input type="button" value="赞(1)">
    <script>
        function $(selector) {
            return document.querySelectorAll(selector);
        }
        function getValue() {
            var num = 2;
            return function () {
                this.value = "赞("+ (num++) +")";
            }
        }
        for(var i = 0; i < $('input').length; i++) {
            $('input')[i].onclick = getValue();
            // 每个按钮都会有一个num的变量，都会有一个方法
        }

    </script>
</body>
</html>